package com.yjt.fresh.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseResultEntity;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.HttpManager;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.listener.HttpOnNextListener;
import com.yjt.fresh.R;
import com.yjt.fresh.api.ApiReturnGoods;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.constant.MyConstants;
import com.yjt.fresh.utils.PreferenceManager;
import com.yjt.fresh.widget.CustomToastResult;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 *
 * Created by mcc on 2018-09-07.
 */

public class AtyToReturnGoods extends BaseSimpleActivity {
    @BindView(R.id.back)
    RelativeLayout mBack;
    @BindView(R.id.edtAppAtyToReturnGoodsExpress)
    EditText mEdtExpress;
    @BindView(R.id.edtAppAtyToReturnGoodsExpressNum)
    EditText mEdtExpressNum;
    @BindView(R.id.edtAppAtyToReturnGoodsAddressDetail)
    EditText mEdtAddressDetail;
    @BindView(R.id.btnAppAtyToReturnGoodsSubmit)
    Button mBtnSubmit;

    @Override
    protected int getContentView() {
        return R.layout.app_aty_to_return_goods;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
    }

    @Override
    protected void initEvent() {
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mBtnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (TextUtils.isEmpty(mEdtExpress.getText().toString())){
                    Toast.makeText(mContext, "请填写快递名称", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (TextUtils.isEmpty(mEdtExpressNum.getText().toString())){
                    Toast.makeText(mContext, "请填写快递单号", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (TextUtils.isEmpty(mEdtAddressDetail.getText().toString())){
                    Toast.makeText(mContext, "请填写退货地址", Toast.LENGTH_SHORT).show();
                    return;
                }

                submit();
            }
        });
    }

    private void submit() {
        ApiReturnGoods apiReturnGoods = new ApiReturnGoods(new HttpOnNextListener<BaseResultEntity>() {

            @Override
            public void onNext(BaseResultEntity baseResultEntity) {
                CustomToastResult.show("提交成功");
                finish();
            }

            @Override
            public void onReLogin() {

            }
        },mContext,true,false,false);

        Map<String,Object> map = new HashMap<>();
        map.put("BACKORDER_ID",getIntent().getStringExtra(MyConstants.ORDER_ID));
        map.put("TITLE","买家 "+ PreferenceManager.getInstance().getUserInfo().getNICKNAME()+"  已经退货");
        map.put("CONTENT","快递公司:  "+mEdtExpress.getText().toString()+
                ";  快递单号:  "+mEdtExpressNum.getText().toString()+
        ";  退货地址:"+mEdtAddressDetail.getText().toString());
        map.put("SESSION_ID",PreferenceManager.getInstance().getUserInfo().getSESSION_ID());
        apiReturnGoods.setMap(map);
        HttpManager.getInstance().doHttpDeal(apiReturnGoods);
    }

}
